public class Vector2D {
    
    private Iterator<List<Integer>> row = null;
    private List<Integer> col = null;
    
    public Vector2D(List<List<Integer>> vec2d) {
        row = vec2d.iterator();
        if(row.hasNext())
            col = vec2d.next().iterator();
    }
    
    public int next() {
        int lastValue = col.next();
        return lastValue;
    }
    
    public boolean hasNext() {
        if(col == null)
            return false;
        if(col.hasNext()) {
            return true;
        } else {
            while(row.hasNext()) {
                col = row.next().iterator();
                if(col.hasNext())
                    return true;
            }
            return false;
        }
    }
    
}